{template 'common/header'}
<ul class="nav nav-tabs">
    <li ><a href="{php echo url('grant/grant/list');}">拨款凭证信息列表</a></li>
    {if $id}<li class="active" ><a href="{php echo url('grant/grant/edit',array('id'=>$id));}">修改拨款凭证信息</a></li>
    {else}
    <li class="active" ><a href="{php echo url('grant/grant/add');}">增加拨款凭证信息列表</a></li>
    {/if}
</ul>
<div class="main">
    <form class="form-horizontal form" action="{$url}" method="post" id="form1">
        <input type="hidden" name="id" value="{$row['id']}" />
        <div class="page-header">
            <h4>拨款凭证信息</h4>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">付款单位全称</label>
            <div class="col-sm-6">
                <input type="text" id="payer" class="form-control" name="payer" value="{$row['payer']}"  placeholder="请输入付款单位全称"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">收款单位全称</label>
            <div class="col-sm-6">
                <input type="text" id="payee" class="form-control" name="payee" value="{$row['payee']}"  placeholder="请输入收款单位全称"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">拨款金额</label>
            <div class="col-sm-6">
                <div class="input-group">
                    <input type="text" id="money" class="form-control" name="money" value="{$row['money']}"  placeholder="请输入拨款金额"/>
                    <span class="input-group-addon">元</span>
                </div>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">用途</label>
            <div class="col-sm-6">
                <input type="text" id="purpose" class="form-control" name="purpose" value="{$row['purpose']}"  placeholder="请输入用途"/>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">凭证图片</label>
            <div class="col-sm-6">
                {php echo tpl_form_field_scan('thumb', $row['thumb']);}
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">发送短信</label>
            <div class="col-sm-6">
                <label for="need_send_1" class="radio-inline"><input type="radio" name="need_send" id="need_send_1" value="1" {if $row['needsend']==1 }checked="checked" {/if} > 是</label>
                <label for="need_send_0" class="radio-inline"><input type="radio" name="need_send" id="need_send_0" value="0" {if empty($row['needsend']) }checked="checked" {/if} > 否</label>
                <div class="help-block">开启此项后，选择需要发送短信的模板及接收人员。</div>
            </div>
        </div>
        <div class="page-header  msgd">
            <h4>短信发送信息</h4>
        </div>
        <div class="form-group msgd">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">接收人员</label>

                <div class="col-sm-6">
                    <table class="table table-hover">
                        <thead class="navbar-inner">
                        <tr>
                            <th>名称</th>
                            <th>手机</th>
                            <th>职务</th>
                            <th style="text-align:right;">操作</th>
                        </tr>
                        </thead>
                        <tbody id="form-items">
                        {loop $selects $item}
                        <tr>
                            <td>{$item['name']} </td>
                            <td>{$item['mobile']}</td>
                            <td>{$item['worktitle']}</td>
                            <td style="text-align:center;width:50px;">
                                <input type="hidden" name="ids[]" value="{$item['id']}"/>
                                <a href="javascript:;" onclick="$(this).parent().parent().remove();" class="btn btn-default btn-sm" title="删除此条目"><i class="fa fa-times"></i></a>
                            </td>
                        </tr>
                        {/loop}
                        </tbody>
                        <tr>
                            <td colspan="4">
                                <a href="javascript:;" onclick="$('#modal-module').modal();"><i class="fa fa-plus"></i> 添加接收人</a>
                            </td>
                        </tr>
                    </table>
                </div>
        </div>
        <div class="form-group msgd">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label">内容模板</label>
            <div class="col-sm-6">
                 <textarea style="height: 78px;" readonly="readonly" class="form-control" name="content">{$row['content']}</textarea>
            </div>
        </div>
        <div class="form-group">
            <label class="col-xs-12 col-sm-3 col-md-3 col-lg-2 control-label"> </label>
            <div class="col-sm-6">
                {if $row['status']==0}
                <button type="submit" class="btn btn-danger" name="submit" value="audit"><i class="fa fa-eye"></i> 提交审核</button>&nbsp;
                {/if}
                <button type="submit" class="btn btn-primary btn-default" name="submit" value="save"><i class="fa fa-save"></i>保存数据</button>

                <input type="hidden" name="token" value="{$_W['token']}" />
            </div>
        </div>
    </form>
</div>
<div id="modal-module" class="modal  fade " role="dialog" tabindex="-1" >
    <div class="modal-dialog"  aria-hidden="true" style=" width:600px;">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button><h3>选择短信接收人</h3>
            </div>
            <div class="modal-body" style="max-height: 300px">
                <div id="module-items"></div>
            </div>

            <div class="modal-footer"><a href="#" class="btn" data-dismiss="modal" aria-hidden="true">关闭</a></div>
        </div>
    </div>
</div>
<script type="text/javascript">
    function search_entries() {
        var ids=getids().join(',');
        $.post("{php echo url('sms/sendee/query')}", {ids:ids}, function(dat){
            $('#module-items').html(dat);
        });
    }
    function getids(){
        var ids=$('#form-items input:hidden[name^="ids"]').map(function () { return $(this).val(); }).get();
        return ids;
    }

    function select_entry(o) {
        var html = '<tr>' +
                '<td>'+o.name+'</td>' +
                '<td>'+ o.mobile+'</td>'+
                '<td>'+ o.worktitle+'</td>'+
                '<td style="text-align:center;width:50px;">'+
                 '<input type="hidden" name="ids[]" value="'+o.id+'"/>'+
                 '<a onclick="$(this).parent().parent().remove();"title="删除"><i class="fa fa-times"></i></a>'+
                '</td></tr>';
        $('#form-items').append(html);
    }
    require(['jquery', 'util'], function($, u){
        {if empty($row['needsend']) }
        $(".msgd").hide();
        {/if}
        $(':radio[name="need_send"]').click(function(){
            if($(':radio[name="need_send"]:checked').val() == '1') {
                $('.msgd').show();
            } else {
                $('.msgd').hide();
            }
        });
        $(':checkbox').each(function(){
            $(this).click(function(){
                if($(this).attr('checked') == 'checked') {
                    $(this).parent().find(':hidden[id="'+$(this).attr('checkvalue')+'"]').val('1');
                } else {
                    $(this).parent().find(':hidden[id="'+$(this).attr('checkvalue')+'"]').val('0');
                }
            });
        });
        $('#modal-module').on('show.bs.modal', function (e) {
            search_entries();
        })
        $("#form1").submit(function(){
            if($("#voucher").val() == '') {
                u.message('凭证图片名称为必填项，请返回修改！', '', 'error');
                return false;
            }
            if($("#payer").val() == '') {
                u.message('付款单位全称为必填项，请返回修改！', '', 'error');
                return false;
            }
            if($("#payee").val() == '') {
                u.message('收款单位全称必填项，请返回修改！', '', 'error');
                return false;
            }
            if($("#content").val() == '') {
                u.message('用途为必填项，请返回修改！', '', 'error');
                return false;
            }
            if($("#money").val() == '') {
                u.message('拨款金额为必填项，请返回修改！', '', 'error');
                return false;
            }

            return true;
        });
    });

</script>
{template 'common/footer'}